package model.juliStaff.tables;

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.util.List;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * @author Maria Julia Racca;
 */
public class ThruthTAlumno extends JTable {

    private JTable correctT;
    private List<Integer> atomicPosition;

    public ThruthTAlumno(JTable correctT, List<Integer> atomicPosition) {
        this.correctT = correctT;
        this.atomicPosition = atomicPosition;

        setDefaultRenderer(Object.class, new ThruthTAlumnoRenderer());
        getTableHeader().setReorderingAllowed(false);
    }

    class ThruthTAlumnoRenderer implements TableCellRenderer {

        @Override
        public Component getTableCellRendererComponent(JTable table,
                                                       Object value, boolean isSelected, boolean hasFocus, int row,
                                                       int column) {

            String correctAnswer = (String) correctT.getValueAt(row, column);

            JLabel label = new JLabel();
            label.setOpaque(true);

            if (atomicPosition != null && isAtomic(column)) {
                label.setText(correctAnswer);
                label.setEnabled(false);

            } else {
                label.setText("");
                label.setEnabled(true);
            }

            return label;
        }

        private boolean isAtomic(int column) {
            int pos = atomicPosition.indexOf(column);
            return pos != -1;
        }

    }

}
